package ursaminor.lazywork.common.core;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;

import org.apache.log4j.Logger;

public class ContextListener implements HttpSessionListener {

	private Logger logger = Logger.getLogger(ContextListener.class.getName());
	
	private static Map<String, Map<String,Object>> container = new HashMap<String, Map<String,Object>>();
	
	public static Map<String, Map<String,Object>> getContainer() { return container; }
	
	@Override
	public void sessionCreated(HttpSessionEvent event) {
		HttpSession session = event.getSession();
		Map<String, Object> dataMap = new HashMap<String, Object>();
		container.put(session.getId(), dataMap);
		logger.info("***********Listener created***************");
	}

	@Override
	public void sessionDestroyed(HttpSessionEvent event) {
		HttpSession session = event.getSession();
		if (session.getAttribute("progress") != null) {
			session.removeAttribute("progress");
		}
		container.remove(session.getId());
		logger.info("***********Listener destroyed***************");		
	}
	
}
